/**
 * 
 * Praktikum CG WP WS13/14
 * Gruppe: Andreas Rebri(andreas.rebri@haw-hamburg.de)
 * 		   Joschka Schulz(joschka.schulz@haw-hamburg.de)
 * Aufgabe : Aufgabenblatt 5
 * Verwendete Quellen: -
 */
package edu.cg7;


import javax.media.j3d.Appearance;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;

import com.sun.j3d.utils.universe.SimpleUniverse;

/**
 * �bernommen aus Aufgabe 1. Erstellt einen Scenengraphen, das Univerum und
 * eine Kugel.
 */
public class Aufgabe7 extends CG1Frame {
	/*
	 * Create the default scene graph.
	 */
	@Override
	protected void createSceneGraph() {
		// Set the view position back far enough so that we can see things
		TransformGroup viewTransform = universe.getViewingPlatform()
				.getViewPlatformTransform();
		Transform3D t3d = new Transform3D();
		t3d.lookAt(new Point3d(10, 10, 20), new Point3d(0, 0, 0), new Vector3d(
				0, 1, 0));
		t3d.invert();
		viewTransform.setTransform(t3d);

		addLight(universe);
		
		//Create WavefrontObjectReader
		WavefrontObjectReader objectReader = new WavefrontObjectReader("cube.obj");
		
		// Erstellung des Meshobjekts
		ITriangleMesh wavefrontObject = objectReader.parseObject();
		Shape3D wavefrontObjectShape = TriangleMeshFactory.createMeshShape(wavefrontObject);

		Appearance WallApp = AppearanceHelper.createShaderAppearance("vertex_shader_env.glsl", "fragment_shader_env.glsl", "environmentmap_forest.jpg");
		wavefrontObjectShape.setAppearance(WallApp);
		
//		AppearanceHelper.setColor(wavefrontObjectShape, new Color3f(1f, 0f, 0f));
		
		scene.addChild(wavefrontObjectShape);

		// Assemble scene
		scene.compile();
		universe.addBranchGraph(scene);
	}

	/**
	 * Setup the lights in the scene. Attention: The light need to be added to
	 * the scene before the scene in compiled (see createSceneGraph()).
	 */
	private void addLight(SimpleUniverse universe) {
		addPointLight(new Point3f(0, 1, 0));
		addPointLight(new Point3f(1, 1, 0));
		addPointLight(new Point3f(0, 1, 1));
	}

	/**
	 * Program entry point.
	 */
	public static void main(String[] args) {
		// Create the central frame
		Aufgabe7 frame = new Aufgabe7();
		// Add content to the scene graph
		frame.createSceneGraph();
	}
}
